
from server import *
import datetime
import time

status = False

class Fujian_ServerHandler(baseServerHandler):        # 创建HJ212服务器

	def recvDataDispose(self, data):
		string = data.decode("ascii")
		print(datetime.datetime.now(),end=":   ")
		print(string)
		if status:
			time.sleep(0.5)
			if 	"CN=2011" in string or \
				"CN=2051" in string or \
				"CN=2061" in string or \
				"CN=2031" in string :
				reply = "##0077QN=20191219172811984;ST=32;CN=9014;PW=123456;MN=88888881234567;Flag=4;CP=&&&&B381\r\n"
				self.sendData(reply.encode("ascii"))
				print(datetime.datetime.now(),end=":   ")
				print("sends:", reply)




if __name__=="__main__":		# 测试程序
	server = TCPServer(port=8000, Handler=Fujian_ServerHandler)
	while True:
		cmd = input("cmd->")
		if cmd == "disconnet":
			server.disconnet()
		elif cmd == "start":
			server.start()
		elif cmd == "print":
			print("server.client:")
			print(server.client)
		elif cmd == "delete":
			print("del server")
			del server
		elif cmd == "getref":
			print(sys.getrefcount(server))
		elif cmd == "stop":
			server.stop()
			print("server.stop()")
		elif cmd == "client":
			print(server.getClientList())
		elif cmd == "open":
			status = True
			print("status = ", status)
		elif cmd == "close":
			status = False
			print("status = ", status)
